import socket


# 创建实例
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 设置地址和端口
ip_port = ("127.0.0.1", 8881)
# 进行连接
# client.connect(ip_port)
# 接收连接成功的消息
# data = client.recv(1024)
# print(data.decode())

# 接收数据
while True:
    msg_input = input("请输入发送的消息：")
    client.sendto(msg_input.encode(), ip_port)
    print('send input msg success')

    if msg_input == 'exit':
        break

    # # 接收第一个消息，即自己发送的消息
    # print('prepare to receive the first msg')
    # data = client.recv(1024)
    # print(data.decode())
    # # 接收第二个消息，一个随机数
    # print('prepare to receive the second msg')
    # data = client.recv(1024)
    # print(data.decode())

# 发送关闭信息
client.close()


# 请输入发送的消息：127.0.0.1
# send input msg success
# 请输入发送的消息：localhost
# send input msg success
# 请输入发送的消息：do you love python?
# send input msg success
# 请输入发送的消息：exit
# send input msg success
#
# Process finished with exit code 0